<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width,user-scalable=no, initial-scale=1">
		<title>CRM</title>
		<link rel="stylesheet" type="text/css" href="../static/azxcrm/css/wap/aui.css" th:href="@{/azxcrm/css/wap/aui.css}" />
		<link rel="stylesheet" type="text/css" href="../static/azxcrm/css/wap/aui.css" th:href="@{/azxcrm/css/wap/mui.min.css}" />
		<link rel="stylesheet" type="text/css" href="../static/azxcrm/css/wap/aui.css" th:href="@{/azxcrm/css/wap/mui.picker.min.css}" />
		<link rel="stylesheet" type="text/css" href="../static/azxcrm/css/wap/aui.css" th:href="@{/azxcrm/css/wap/perfect_order.css}" />
<!-- 		<link rel="stylesheet" type="text/css" href="/azxcrm/css/wap/new_order.css" th:href="@{/azxcrm/css/wap/new_order.css}"/> -->
        <link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_835360_8flqp9ignrc.css"/>
        <script src="/azxcrm/js/wap/mui.min.js" th:src="@{/azxcrm/js/wap/mui.min.js}" type="text/javascript" charset="utf-8"></script>
        <script src="/azxcrm/js/wap/mui.picker.min.js" th:src="@{/azxcrm/js/wap/mui.picker.min.js}" type="text/javascript" charset="utf-8"></script>
        <script src="../static/js/jquery.min.js" th:src="@{/js/jquery.min.js}"></script>
        <script th:inline="javascript"> var ctx = [[@{/}]]; </script>   
	</head>
	<body>
		 	<!--头部结构-->
	<div class="g-head">
	    <header class="aui-bar aui-bar-nav">
			<a class="aui-pull-left aui-btn"  href="javascript:history.go(-1)">
			    <span class="iconfont icon-fanhui1"></span>返回
			</a>
			<div class="aui-title">完善订单</div>
		</header>
	</div>
    <!--头部结构-->
    
    <!--订单编写结构-->
    <form id="add_order">
    <div class="aui-content aui-margin-b-15">
	    <ul class="aui-list aui-list-in">
	        <li class="aui-list-item">
	            <div class="s-order">
	                <div>订单编号：</div>
	                <div><span th:text="${order.orderNum}"></span></div>
	            </div>
	        </li>
	        <li class="aui-list-item">
	            <div class="s-order">
	                <div>订单类型：</div>
	                <div><span th:text="${order.typeName}"></span></div>
	            </div>
	        </li>
	    </ul>
	</div>
     <!--订单编写结构-->

     <!--客户信息结构-->
     <div class="aui-content aui-margin-b-15 g-order">
	    <ul class="aui-list aui-list-in">
	        <li class="aui-list-header sale_pro">
	        	<div class="s-order">
	        		<div><img src="../azxcrm/image/wap/customer.png"/></div>
	        		<div>客户信息</div>
	        	</div>
	        </li>
	        <li class="aui-list-item">
	            <div class="s-order">
	                <div>客户姓名：</div>
	                <div><span th:text="${order.customerClue.customerName}"></span></div>
	            </div>
	        </li>
	        <li class="aui-list-item">
	            <div class="s-order">
	                <div>手机号码：</div>
	                <div><span th:text="${order.customerClue.customerCellphone}"></span></div>
	            </div>
	        </li>
	        <li class="aui-list-item">
				<div class="s-order">
				    <div>身份证号：</div>
				    <div><span th:text="${order.customerClue.customerIdentityNum}"></span></div>
				</div>
	        </li>
	    </ul>
	</div> 	
     <!--客户信息结构-->
     
    <!--未成单结构-->
	<div class="aui-content aui-margin-b-15 g-order2">
		<ul class="aui-list aui-form-list" id="parent">
	        <li class="aui-list-header sale_pro">
				<div class="s-order">
					<div><img src="../azxcrm/image/wap/saler_product.png"/></div>
					<div>销售产品</div>
				</div>
	        </li>
			<li class="aui-list-item" id="child">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-input icon--jia iconfont" id="add">添加产品信息</div>
                </div>
            </li>
	    </ul>
	    <ul class="aui-list aui-form-list" id="list"></ul>
	</div>
	<footer class="aui-bar aui-bar-tab" id="footer">
	    <input type="hidden" name="typeId" id="typeId">
        <input type="hidden" name="typeName" id="typeName" >
        <input type="hidden" name="productId" id="productId" >
        <input type="hidden" name="fullName" id="fullName" >
        <input type="hidden" id="orderId" name="orderId" th:value="${order.orderId}">
        <input type="hidden" id="status" name="status" th:value="${status}">
        <button type="button" class="aui-bar aui-bar-tab" id="toastBtn" onclick="return check(this.form)">确认提交审核 </button>            
    </footer>
    </form>
	<!--未成单结构-->
	</body>
</html>
<script type="text/javascript">
        var getOrderType,getProduct,getProductInfo;  /* 定义三个全局变量用于接受数据 */  
		var add = document.getElementById('add');	
		var list = document.getElementById("list")
		var parent =  document.getElementById("parent")
		var child = document.getElementById("child")
		var orderId = document.getElementById("orderId").value;
		var picker = new mui.PopPicker({
		    layer: 3
		});

		add.addEventListener('tap', function() {          
            $.ajax({
                cache : true,
                type : "get",
                url : ctx + "/wap/getOrderType",
                data :'',
                async : false,
                error : function(res) {                 
                    mui.toast("系统错误");
                    return false;
                },
                success : function(data) {  
                    getOrderType = data;                
                    $.ajax({
                        cache : true,
                        type : "get",
                        url : ctx + "/wap/getProductSpecification",
                        data :'',
                        async : false,
                        error : function(res) {
                            mui.toast("系统错误");
                            return false;
                        },
                        success : function(data) {  
                            getProduct = data;                              
                            $.ajax({
                                cache : true,
                                type : "get",
                                url : ctx + "/wap/getProductInfo",
                                data :'',
                                async : false,
                                error : function(res) {
                                    mui.toast("系统错误");
                                    return false;
                                },
                                success : function(data) {  
                                    getProductInfo = data;      
                                
                                }
                            });                                                     
                        }
                    });                             
                }
            });
            
            
            picker.setData(getSelectData(getOrderType,getProduct,getProductInfo));
            picker.show(function(items) {
                parent.removeChild(child);          
                document.getElementById('typeId').value = items[0].value;
                document.getElementById('typeName').value = items[0].text;
                document.getElementById('productId').value = items[2].value; 
                document.getElementById('fullName').value = items[2].fullName;
                var data = items[0].text+'-'+items[1].text+'-'+items[2].text;   
                
                var money = items[2].money;
                var month = items[2].month;          
                var product = "<li class='aui-list-item'><div class='aui-list-item-inner'><div class='s-order'><div class='aui-list-item-title'>销售产品：</div><div class='aui-text'>"+data+"</div></div></li>"+
                              "<li class='aui-list-item'><div class='aui-list-item-inner'><div class='s-order'><div class='aui-list-item-title'>金额(￥)：</div><div class='aui-text'>"+money+"</div></div></li>"+
                              "<li class='aui-list-item'><div class='aui-list-item-inner'><div class='s-order'><div class='aui-list-item-title'>使用期限：</div><div class='aui-text'>"+month+"</div></div></li>"           
                list.innerHTML=product;             
            }) 
            
            })
        
        function check(form) {
			var status = document.getElementById("status").value;
            if(form.typeName.value==''){
               mui.toast('产品信息必选');
                 return false;
              }else{
                $.ajax({
                cache : true,
                type : "POST",
                url : ctx + "/wap/saveOrder",
                data : $("#add_order").serialize(),
                async : false,
                error : function(request) {
                    mui.toast("系统错误");
                },
                success : function(data) {
                    if (data.code == 0) {
                        mui.toast("提交成功");
                        if(status==0){
                       	 $("#toastBtn").removeAttr("onclick");
                            setTimeout(function(){
                            	window.location.href= ctx + "indexWap"
                                },2200)
                        }else if(status == 1){
                       	 $("#toastBtn").removeAttr("onclick");
                       	 setTimeout(function(){
                                window.location.href= ctx + "/wap/wapMy"
                                },2200)
                        }
                    } else {
                        mui.toast("提交失败");
                    }
                }
                });
             }     
       }
        function getSelectData(data1,data2,data3){
            var arr1 = {},arr2 = {},arr3 = {};
            //一级数据
            for (var i=0;i<data1.length;i++) {
                arr1[data1[i].dictCode] = {
                    text:data1[i].dictLabel,
                    value:data1[i].dictCode,                    
                    children:{},
                    _index:i,
                }
            }
            for (var j=0;j<data2.length;j++) {
                arr1[data2[j].typeId].children[data2[j].specId]={
                    text:data2[j].specName,
                    value:data2[j].specId,
                    children:[]
                }           
            }
            
            for (var k=0;k<data3.length;k++) {
                arr1[data3[k].typeId].children[data3[k].specId].children.push({
                    text:data3[k].productName,
                    value:data3[k].productId,
                    money:data3[k].productPrice,
                    month:data3[k].productTerm,
                    fullName:data3[k].fullName
                })
            }
            
            var arr2=[],o1,o2;
            for(o1 in arr1){
                arr2.push({
                    text:arr1[o1].text,
                    value:arr1[o1].value,
                    children:[]
                })
                for(o2 in arr1[o1].children){
                    arr2[arr1[o1]._index].children.push(arr1[o1].children[o2])
                }
            }
            
            return arr2
        }
</script>